<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/24 0024
 * Time: 11:34
 */
$dom = new DOMDocument();
$dom->load('./test.xml');
$root = $dom->documentElement;

process_children($root);

function process_children($node)
{
    $children = $node->childNodes;

    foreach ($children as $elem) {
        if ($elem->nodeType == XML_ELEMENT_NODE) {

//            echo $elem->nodeName.PHP_EOL;
            if ($elem->nodeName == 'body') {
                echo $elem->getAttributeNode('background')->value.PHP_EOL;
            }
            process_children($elem);
        }
    }
}